<template>
  <div class="game">
    <h2>游戏姓名:{{name}}</h2>
    <h2>游戏地址:{{address}}</h2>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
    name:'Game',
    data(){
        return{
            name:'光与夜之恋',
            address:'光启市'
        }
    },
    methods:{
        demo(msgName,data){
            console.log('有人发布了hello消息,回调执行了',msgName,data)
        }
    },
    mounted(){
        /* this.$bus.$on('hello',(data)=>{
            console.log('我是Game组件,我收到了数据',data)
        }) */
        /* this.pubId = pubsub.subscribe('hello',(msgName,data)=>{
            console.log('有人发布了hello消息,回调执行了',msgName,data)
        }) */
        this.pubId = pubsub.subscribe('hello',this.demo)
    },
    beforeDestroy(){
        // this.$bus.$off('hello')
        pubsub.unsubscribe(this.pubId)
    }
}
</script>

<style>
    .game{
        background-color: skyblue;
        padding:5px;
    }
</style>